package com.consult.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.consult.config.dto.AjaxResult;
import com.consult.entity.RegisterRecord;
import com.consult.service.IRegisterRecordService;
import com.consult.utils.TokenUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-06-26
 */
@RestController
@RequestMapping("/registerRecord")
public class RegisterRecordController {

    @Resource
    private IRegisterRecordService registerRecordService;

    @PostMapping("/add")
    public AjaxResult addRegister(@RequestBody RegisterRecord registerRecord, HttpServletRequest request) {
        Long userId = TokenUtil.getUserId(request);
        registerRecord.setStuId(userId);
        registerRecordService.save(registerRecord);
        return AjaxResult.success();
    }

    @PostMapping("/page")
    public AjaxResult getRegisterPage(@RequestBody Page<RegisterRecord> page) {
        page = registerRecordService.getRegisterPage(page);
        return AjaxResult.success(page);
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody RegisterRecord registerRecord) {
        registerRecordService.updateById(registerRecord);
        return AjaxResult.success();
    }
}

